<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@ page language="java" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c"%>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<jsp:include page="/common/commonCss.jsp"/>
<jsp:include page="/common/commonJs.jsp"/>
<script language="javascript" src="${basePath }commonJs/tags/My97DatePicker/WdatePicker.js"></script>
<script language="javascript" src="${basePath }commonJs/system/update_pwd.js"></script>
<script language="javascript" src="${basePath }commonJs/quinn_commons.js"></script>
<script type="text/javascript">
var basePath = '${basePath}';
	$(document).ready(function() {
		var message = "${message}";
		if(message != null && message !="")
			alertInfo(message);
		$("#leaveList_class").addClass("content_hover");
		//$("#leaveType").empty();
		loadLeaveType();
		$("#createLeave").click(function() {
			var isPass = "${isPass}";
			if(isPass == '1'){
				alertInfo("该角色不需要进行请假流程操作");
				return false;
			}else{
				window.location.href = "${basePath}workflow/leave/createLeave.shtml";
			}
		});
		
		excutePage();
		
	});
	
	function select11(){
		$("#searchForm input:hidden[name='pageNo']").val(1);
		excutePage();
	}
	
	//分页
	function excutePage(){
		 var form = $("#searchForm"); //获取一个form的jquery对象
	     var pagebean = new PageBean(form); //实例化一个Pagebean对象，并且设置form对象
	     pagebean.setTableId("table1"); //设置要分页的table的id属性
	     pagebean.setCallback(initTable); //回调函数
	     pagebean.setFootId("pagefoot"); //foot div的id
	     setPagebeanObj(pagebean); //全局化pageBean对象
	     pagebean.doPage(); 
	 } 
	//回调函数,只有一个参数，data为返回数据结果集，也就是MyBatisSuperModel里的results
    //开发人员需要在此函数里写自己的数据填充逻辑,把数据拼到table里
    //注意:分页插件会把table除了第一行和最后一行都删掉，这里填充数据时需要从第二行开始填充
    function initTable(data) {
           $.each(data, function(ind, obj) {
        	   			obj = emptyJson(obj);
        	   			obj2 = emptyJson(obj.workflowVo);
                        var htm = "<tr>";
                        htm += "<td class=\"lv\"><a href=\"${basePath }workflow/leave/detailLeave.shtml?id="+obj.pkLeaveId+"\">"+obj.pkLeaveId+"</a></td>";
                        htm += "<td>" + obj.applyName + "</td>";
                        htm += "<td>" + obj.applyTime + "</td>";
                        htm += "<td>" + obj.leaveType + "</td>";
                        htm += "<td>" + obj.leaveTime + "</td>";
                        htm += "<td>" + obj2.statusDesc + "</td>";
                        htm += "<td>" + obj2.result + "</td>";
                        if(obj.status == '1')
                        	htm += "<td class=\"lv\">"+
                        						"<input type='button' id='editBtn' class=\"btn_l\" value='编辑' onclick=\"editLeave('"+obj.pkLeaveId+"')\"/>&nbsp;&nbsp;&nbsp;"+
                        						"<input type='button' id='deleteBtn' class='btn_l' value='删除' onclick=\"deleteLeave('"+obj.pkLeaveId+"')\"/></td>";
                        else{
                        	if(obj.status == '2'){
 									if(obj2.isCurrtOpt == '1'){
 										if(obj2.isStartUser == '1')
 											htm += "<td class=\"lv\"><input type='button' id='completeBtn' class=\"btn_l\" value='重新申请' onclick=\"completeLeave('"+obj.pkLeaveId+"')\"/></td>";
 										else
 											htm += "<td class=\"lv\"><input type='button' id='completeBtn' class=\"btn_l\" value='处理' onclick=\"completeLeave('"+obj.pkLeaveId+"')\"/></td>";	
 									}else
 										htm += "<td></td>";
                        	}else{
                        		htm += "<td></td>";
                        	}
                        } 
                        htm += "</tr>";
                        $("#table1").find("tr:eq("+ind+")").after(htm);
           });
      }
	
	//页面进入就加载请假类型列表
	function loadLeaveType(){
		$.ajax({  
            type: "get",  
            url: "${basePath }workflow/leave/findLeaveTypeList.shtml",  
            cache: false,
	        async: false,
	        dataType: 'json',  
            data: {},  //没参数可以删除
            success: function (data) {
            	
            	$("#leaveType").append("<option value=''>全部</option>");
            	var type = $("#leaveType").val();
            	$(data).each(function(n){
            		if(this.key == type)
            			$("#leaveType").append("<option value='"+this.key+"' selected>"+this.value+"</option>");
            		else
            			$("#leaveType").append("<option value='"+this.key+"'>"+this.value+"</option>");
    		    });   
            	refreshSelect();
            } ,
            error : function(XMLHttpRequest) {
				ajaxError(XMLHttpRequest);
			}
        });  
		
	}
	

	function deleteLeave(id){
		if(confirm("确定要删除数据吗？")){
			window.location.href = "${basePath }workflow/leave/updateLeave.shtml?pkLeaveId="+id+"&btnType=5";
		 }
	}
	
	function editLeave(id){
		window.location.href = "${basePath }workflow/leave/detailLeave.shtml?id="+id+"";
	}
	
	function completeLeave(id){
		window.location.href = "${basePath }workflow/leave/detailLeave.shtml?id="+id+"";
	}
	
</script>
<title>嘉童游乐中心</title>
</head>
<body class="bg">

<div class="content m_auto">
	<%@include file="../indexPage/index_tab.jsp"%>
    <div class="content_r mt10">
    	<div class="p20">
    	<form action="${basePath }workflow/leave/findLeaveList.shtml" method="post" id="searchForm" name="searchForm">
    	<input type="hidden" name="pageSize" value="10" />
    	<input type="hidden" name="pageNo" value="1" />
    	<div class="file_single_dl f14 fixed">
        	<dl class="fixed" style="overflow:hidden">
                <dd><label>申请人：</label><input type="text" class="iput_t w200" name="applyName" /></dd>
                <dd><label>请假类型：</label>
                    <div class="uboxstyle">
                         <select name="type" id="leaveType">
                    	</select>
                    </div>
                </dd>
                <dd><label>请假时间：</label>
                    <input title="" type="text" name="startTime" id="date1"
					onclick="WdatePicker({dateFmt:'yyyy/MM/dd',maxDate:'#F{$dp.$D(\'date2\')}',isShowWeek:true,isShowClear:true,readOnly:true})"
					class="Wdate iput_t w82" readonly="readonly" /><span class="mlr5">至</span><input title="" type="text" name="endTime" id="date2"
					onclick="WdatePicker({dateFmt:'yyyy/MM/dd',minDate:'#F{$dp.$D(\'date1\')}',isShowWeek:true,isShowClear:true,readOnly:true})"
					class="Wdate iput_t w82" readonly="readonly" />
                </dd>
            </dl>
            <div>
            	<input type="button" id="searchBtn" class="btn fr m010" value="查询" onclick="select11();" />
            	<shiro:hasPermission name="leave:createLeave">
            		<input type="button" class="btn fr m010" id="createLeave" value="创建请假申请" />
            	</shiro:hasPermission>
            </div>
        </div>
        </form>
        
        <div class="tab_normal mt10">
            <table class="table" id="table1">
                <tr>
                    <th>申请编号</th>
                    <th>申请人</th>
                    <th>申请时间</th>
                    <th>请假类型</th>
                    <th>请假时间</th>
                    <th>审批状态</th>
                    <th>审批结果</th>
                    <th>操作</th>
                </tr>
                	
            </table>
            <!---翻页-->
            <div class="page fr m10" id="pagefoot">
            </div>
    	</div>
        </div>
    </div>
</div>

</body>
</html>